//
//  AlarmStatisticsCell.swift
//  SBSafetyApp
//
//  Created by Lina on 2023/4/27.
//

import Foundation
import UIKit

class AlarmStatisticsCell: UICollectionViewCell {
    let iconIV = UIImageView()
    let nameL = UILabel()
    let numL = UILabel()

    override init(frame: CGRect) {
        super.init(frame: .zero)
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    /*
     enum AlarmType: String {
         case robbery = "0" // 劫警
         case burglary = "1" //  盗警
         case fire = "2" // 火警
         case electricity = "3" // 电
         case shock = "4" // 震动
         case unalarm = "5" // 撤防
         case alarm = "6" // 布防
     }

     */
    
    func reload(withModal modal: AlarmStaticsTypeListModal) {
        switch AlarmType(rawValue: modal.dictValue ?? "") {
        case .robbery:
            iconIV.image = UIImage(named: "ic_alarm_report1")
        case .burglary:
            iconIV.image = UIImage(named: "ic_alarm_report2")
        case .fire:
            iconIV.image = UIImage(named: "ic_alarm_report3")
        case .electricity:
            iconIV.image = UIImage(named: "ic_alarm_report4")
        case .shock:
            iconIV.image = UIImage(named: "ic_alarm_report5")
        case .unalarm:
            iconIV.image = UIImage(named: "ic_alarm_report6")
        case .alarm:
            iconIV.image = UIImage(named: "ic_alarm_report6")
        default:  break
        }
        nameL.text = modal.dictLabel
        numL.text = "\(modal.total ?? 0)"
    }
    
    func setupUI() {
        addSubview(iconIV)
        iconIV.snp.makeConstraints { make in
            make.top.equalToSuperview()
            make.centerX.equalToSuperview()
            make.width.height.equalTo(45)
        }
        
        nameL.font = .systemFont(ofSize: 13)
        nameL.textColor = .hex("#666666")
        nameL.numberOfLines = 0
        nameL.textAlignment = .center
        addSubview(nameL)
        nameL.snp.makeConstraints { make in
            make.top.equalTo(iconIV.snp.bottom).offset(10)
            make.left.right.equalToSuperview()
        }
        
        numL.font = .systemFont(ofSize: 13)
        numL.textAlignment = .center
        numL.textColor = .black
        numL.numberOfLines = 0
        addSubview(numL)
        numL.snp.makeConstraints { make in
            make.top.equalTo(nameL.snp.bottom).offset(8)
            make.left.right.equalToSuperview()
        }
    }
}
